package com.zhang.controller;


import com.zhang.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/respanse")
public class RspanseController {

    //响应页面~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    //字符串
    @RequestMapping("test1")
    public String test1(){
        return "info";
    }

    //ModelAndView
    @RequestMapping("test2")
    public ModelAndView test2(ModelAndView modelAndView){

        User user = new User("张飞", "123");
        modelAndView.addObject(user);
        modelAndView.setViewName("info");

        return modelAndView;
    }


    //响应数据~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    //响应字符串
    @RequestMapping("test3")
    @ResponseBody
    public String test3(){
        return "hello";
    }



    //响应对象或集合(自动将对象转为json)
    @RequestMapping("test4")
    @ResponseBody
    public User test4(){
        User user = new User("张飞", "123");

        return user;
    }







}


